package com.lins.storedisk.controller;

import com.lins.storedisk.bo.FileBo;
import com.lins.storedisk.dto.FileDTO;
import com.lins.storedisk.dto.SearchDTO;
import com.lins.storedisk.dto.TreeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author linshuo
 * @Date 2023/12/4 13:09
 */
@Slf4j
@RestController
@RequestMapping("file")
public class FileController {

    @Autowired
    FileBo fileBo;

    @PostMapping("upload")
    public List<String> upload(@RequestParam("file") MultipartFile[] file, String parUrl) {
        return fileBo.upload(file,parUrl);
    }

    @RequestMapping("download")
    public void download(Integer fid, HttpServletResponse response) {
        fileBo.download(fid,response);
    }

    @PostMapping("findList")
    public List<FileDTO> findList(@RequestBody SearchDTO dto) {
        return fileBo.findList(dto);
    }

    @PostMapping("delete")
    public Integer delete(Integer fid) {
        return fileBo.delete(fid);
    }

    @PostMapping("saveFloder")
    public Integer saveFloder(String floderName,String parUrl) {
        return fileBo.saveFloder(floderName, parUrl);
    }

    @PostMapping("rename")
    public Integer rename(Integer fid,String newName) {
        return fileBo.rename(fid,newName);
    }

    @GetMapping("findTree")
    public List<TreeDTO> findTree() {
        return fileBo.findTree();
    }

    @PostMapping("move")
    public Integer move(Integer fid,Integer pid) {
        //被移动的文件id，目标文件夹id
        return fileBo.move(fid,pid);
    }

    @GetMapping("changeShare")
    public Integer changeShare(Integer fid,Integer uid) {
        return fileBo.changeShare(fid, uid);
    }
}
